<?php

namespace App\Admin\Forms;

use App\Clients\CrmClient;
use Dcat\Admin\Form\EmbeddedForm;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;

class ArchiveSettingForm extends Form
{

    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        if (!\Admin::user()->can('setting.change'))
            return $this->response()->error('没有权限');

        admin_setting($input);
        return $this
            ->response()
            ->success('保存配置成功');
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->confirm('保存建档表单配置', '');

        $this->multipleSelect('hide_fields', '咨询隐藏字段')
            ->options([
                'source' => admin_trans('clue.fields.source'),
                'site_name' => admin_trans('clue.fields.site_name'),
                'post_date' => admin_trans('clue.fields.post_date'),
                'ad_name' => admin_trans('clue.fields.ad_name'),
                'url' => admin_trans('clue.fields.url'),
                'ip' => admin_trans('clue.fields.ip'),
                'location' => admin_trans('clue.fields.location'),
                'question_data' => admin_trans('clue.fields.question_data')
            ]);
        $this->switch('hidden_archive_source','隐藏咨询建档选择媒介的能力')->default(0);
        $this->switch('display_wechat', '显示微信字段');
        $this->switch('display_qq', '显示QQ字段');
        $this->select('Province', '建档默认省份')
            ->options(getProvince()->pluck('name', 'code'))
            ->load('City', admin_route("admin.api.city"))
            ->required();
        $this->width(4)
            ->select('City', '建档默认城市')
            ->load('Area', admin_route("admin.api.area"))
            ->required();
        $this->width(4)
            ->select('Area', '建档默认区域')
            ->required();
        $this->textarea('comment_example', '备注默认模板');

        $this->disableResetButton();
        if (!\Admin::user()->can('setting.change'))
            $this->disableSubmitButton();

    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return admin_setting()->toArray();
    }
}
